package com.thiswhyme.ratelimiter.config;

import com.thiswhyme.ratelimiter.core.LimitHandler;
import com.thiswhyme.ratelimiter.core.RateLimitAspectHandler;
import com.thiswhyme.ratelimiter.core.impl.RedisLimitHandler;
import org.redisson.api.RedissonClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 限流器配置
 * @author: thiswhyme
 * @date: 2021/8/30
 */
@Configuration
@EnableConfigurationProperties(RateLimiterProperties.class)
public class RateLimiterAutoConfiguration {

    @Bean
    public LimitHandler redisLimitHandler(RedissonClient redissonClient, RateLimiterProperties properties) {
        return new RedisLimitHandler(redissonClient, properties);
    }

    @Bean
    public RateLimitAspectHandler rateLimitAspectHandler(LimitHandler limitHandler) {
        return new RateLimitAspectHandler(limitHandler);
    }
}
